package com.cl.master.config;

import com.cl.master.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author xc
 * @Date 2023/3/25 22:07
 * @Version 1.0
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer{
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        /*初始网站自动进入登录页面*/
        registry.addViewController("/").setViewName("my/login");
        /*用于登录操作后进入主页面*/
        registry.addViewController("/main.html").setViewName("main/index");
        /*用于退出登录后重新进入登录页面*/
        registry.addViewController("/login.html").setViewName("my/login");
        /*用于进入注册页面*/
        // /*注册信息*/
        // registry.addViewController("/end").setViewName("my/reg");
        /*侧边栏按钮转发路径*/
        registry.addViewController("/toIndex").setViewName("main/index");
        registry.addViewController("/toReport").setViewName("main/report");

        registry.addViewController("/toWater").setViewName("main/waterlineDetection");
        registry.addViewController("/toMap").setViewName("main/map");

            registry.addViewController("/toWatch").setViewName("main/watchSystem");

        registry.addViewController("/toLogin").setViewName("my/login");
        registry.addViewController("/toPersonal").setViewName("my/personal");
        registry.addViewController("/toNotes").setViewName("my/notes");

        registry.addViewController("/toSensor").setViewName("manage/sensor");
        registry.addViewController("/toWaterQuality").setViewName("manage/waterQuality");
        registry.addViewController("/toHistory").setViewName("manage/history");
        /*企业管理请求路径*/
        registry.addViewController("/toAddCompany").setViewName("company/addCompany");


        // registry.addViewController("/toData").setViewName("data/data");
        // registry.addViewController("/toDataSec").setViewName("data/dataSec");
        // registry.addViewController("/toDataThd").setViewName("data/dataThd");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /*添加登录拦截器*/
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/js/**","/image/**","/font/**","/css/**","/","/login","/login.html","/reg","/reg.html","/end");
    }
}
